<!DOCTYPE html>
<html >
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="css/style.css" />
	<script type="text/javascript" src="js/index.js"></script>
	<title>动物管理系统</title>
</head>
<body>
	<h1>动物管理系统</h1>
	<table>
		<tr>
			<td>名称：</td>
			<td>
				<input type="text" name="name" />
			</td>
		</tr>
		<tr>
			<td>科属：</td>
			<td>
				<input type="text" name="ks" />
			</td>
		</tr>
		<tr>
			<td>品种：</td>
			<td>
				<input type="text" name="pz" />
			</td>
		</tr>
		<tr>
			<td>是否珍惜：</td>
			<td>
				<input type="text" name="sfzx" />
			</td>
		</tr>
		<tr>
			<td colspan="5">
				<button onclick="update()">修改</button>
			</td>
		</tr>
	</table>
	<script type="text/javascript">
		let id;
		window.onload=function(){
			id = window.location.search.substring(1).split("=")[1];
		//	alert(id);
			let ajax = getAjax();
			ajax.open("GET","./server/select_server.php?id=" + id,false);
			ajax.send();
			let data = JSON.parse(ajax.responseText);
		//	console.log(data);
			document.getElementsByName("name")[0].value = data.name;
			document.getElementsByName("ks")[0].value = data.ks;
			document.getElementsByName("pz")[0].value = data.pz;
			document.getElementsByName("sfzx")[0].value = data.sfzx;
		}
		function update(){
			let name=document.getElementsByName("name")[0].value;
			let ks=document.getElementsByName("ks")[0].value;
			let pz=document.getElementsByName("pz")[0].value;
			let sfzx=document.getElementsByName("sfzx")[0].value;
			let ajax=getAjax();
			ajax.open("POST","./server/update_server.php", false);
			ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=UTF-8");
			ajax.send("id="+id+ "&name="+name+"&ks="+ks+"&pz="+pz+"&sfzx="+sfzx);
			alert(ajax.responseText);
			window.location.href="index.php";
		}
	</script>
</body>
</html>
